package com.watson.bloom;

import com.google.common.base.Charsets;
import com.google.common.hash.Funnel;
import com.google.common.hash.PrimitiveSink;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: mytest
 * @description: funnel
 * @author: zhangpeng348@jd.com
 * @date: 2018-12-10 20:36
 **/
public class MyFunnel implements Funnel<String> {

    private static final long serialVersionUID = 1L;

    @Override
    public void funnel(String s, PrimitiveSink primitiveSink) {
        primitiveSink.putString(s, Charsets.UTF_8);
    }

    public static void main(String[] args) {
        String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        System.out.println(format);
        List<String> name = new ArrayList<>();
        name.add("aa");
        name.add("bb");
        name.add(null);
        System.out.println(name);

        StringBuilder eleList = new StringBuilder().append("(\"");
        for (String nam : name) {
            eleList.append(nam != null ? nam : "").append("\",\"");
        }
        eleList.delete(eleList.toString().length()- 2, eleList.toString().length())
                .append(")");
        String columns =
                name.toString()
                        .replace('[', '(')
                        .replace(']', ')');
        StringBuilder sql = new StringBuilder();
        //eg.: insert into gx_pv_data_test_1_1 partition (dt='2018-12-26') (fpid,chid)values('a','b');
        sql.append("insert into ").append("abcdb")
                .append(" partition (dt='").append(format).append("') ")
                .append(columns)
                .append("values")
                .append(eleList.toString());
        System.out.println(sql.toString());

    }
}
